package com.oolatina;

import com.oolatina.activity.MainActivity;

import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.ImageView;
import android.annotation.TargetApi;
import android.content.Context;
import android.widget.LinearLayout;
import android.view.Display;
import android.view.WindowManager;
import android.view.Gravity;
import android.graphics.Bitmap;
import android.os.Build;
import android.util.Log;

// Framework http://studio.shua-creation.com - v1.0 Android
// Code by Jérôme Laurent Copyright Studio Shua-Creation 2014
// Classe pour faire une NavigationBar de basique

public class SCNavigationBar
{
    ImageView background;
    TextView texte;
    int ScreenWidth;
    int ScreenHeight;

	public void init(FrameLayout layout, Context thisContext, MainActivity mainactivity)
    {
        // Recuperation de la largueur de l'ecran
        WindowManager wm = (WindowManager) thisContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        ScreenWidth = display.getWidth();
        ScreenHeight = display.getHeight();
        
        // Initialisation du background & du texte
        background = new ImageView(thisContext);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ScreenWidth, 60);
        layoutParams.setMargins(0,0,0,0);
        background.setBackgroundColor(Color.rgb(0, 0, 0));
        background.setLayoutParams(layoutParams);
        //mainactivity.getActionBar().setCustomView(background);
        layout.addView(background);

        texte = new TextView(thisContext);
        texte.setText("");
        texte.setLayoutParams(layoutParams);
        texte.setTextColor(Color.rgb(255,255,255));
        texte.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
        //mainactivity.getActionBar().setCustomView(background);
        layout.addView(texte);
    }

    public void SetBackgroundColor(int red,int green,int blue)
    {
        background.setBackgroundColor(Color.rgb(red,green,blue));
    }

    // getressource qui foire à corriger
    public void SetBackgroundImage(String filename)
    {
        //Bitmap bmp = BitmapFactory.decodeResource(getResources(),filename);
        //background.setImageBitmap(bmp);
    }

    public void SetSize(int width,int height)
    {
        background.getLayoutParams().width = width;
        background.getLayoutParams().height = height;
        texte.getLayoutParams().width = width;
    	texte.getLayoutParams().height = height;
    }
    
    public void SetPourcentSize(int width, int height)
    {
    	float radioWidth = (float)ScreenWidth/100;
    	float radioHeight = (float)ScreenHeight/100;
    	background.getLayoutParams().width = (int)(radioWidth*width);
    	background.getLayoutParams().height = (int)(radioHeight*height);
    	texte.getLayoutParams().width = (int)radioWidth*width;
    	texte.getLayoutParams().height = (int)radioHeight*height;
    }
    
    public int SetPourcentWidth(int width)
    {
    	float radioWidth = (float)ScreenWidth/100;
    	background.getLayoutParams().width = (int)(radioWidth*width);
    	texte.getLayoutParams().width = (int)radioWidth*width;
    	return (int)radioWidth*width;
    }
    
    public int SetPourcentHeight(int height)
    {
    	float radioHeight = (float)ScreenHeight/100;
    	background.getLayoutParams().height = (int)(radioHeight*height);
    	texte.getLayoutParams().height = (int)radioHeight*height;
    	return (int)radioHeight*height;
    }

    public void SetTitleColor(int red,int green,int blue)
    {
        texte.setTextColor(Color.rgb(red,green,blue));
    }

    public void SetTitleFontSize(int size)
    {
        texte.setTextSize(size);
    }

    public void SetTitle(String title)
    {
        texte.setText(title);
    }
}
